<?php
/*! \brief
 * This is AWidgetPoolFactory class
 * This is the Simple Factory Class that generate widget pool relative object
 * And shot cut of widget pool relative object 
 * \author William Su
 */
require_once dirname(__FILE__) . '/WidgetPoolFactory.interface.php';
abstract class AWidgetPoolFactory implements IWidgetPoolFactory
{
    protected static $instance;
    /**
     * @var WF
     */
    protected $objFramework;
    public function __construct($objFramework){
        $this->objFramework = $objFramework;
    }
    public static function getDirnameFile(){
        if(! isset(self::$instance[__FUNCTION__])){
            self::$instance[__FUNCTION__] = dirname(__FILE__);
        }
        return self::$instance[__FUNCTION__];
    }
    /**
     *\brief Description
     * This method will return object of WFWidgetPoolDB
     * @return WFWidgetPoolDB
     */
    public function getWidgetPoolDB(){
        if(! isset(self::$instance[__FUNCTION__])){
            require_once (self::getDirnameFile() . '/db/WidgetPoolDB.php');
            self::$instance[__FUNCTION__] = new WFWidgetPoolDB($this->objFramework);
        }
        return self::$instance[__FUNCTION__];
    }
    /**
     *\brief Description
     * This method will return object of WFDataObject
     * @return WFDatabaseObjectSqlite
     */
    public function getDataObject($strDbName = null){
        return $this->objFramework->getDataObject($strDbName);
    }
    /**
     *\brief Description
     * This method will return object of WFWidgetPoolOpt
     * @return WFWidgetPoolOpt
     */
    public function getWidgetPoolOpt(){
        if(! isset(self::$instance[__FUNCTION__])){
            require_once (self::getDirnameFile() . '/config/WidgetPoolOpt.php');
            self::$instance[__FUNCTION__] = new WFWidgetPoolOpt($this->objFramework);
        }
        return self::$instance[__FUNCTION__];
    }
    /**
     *\brief Description
     * This method will return object of WFWidgetPoolManager
     * @param $strUpdateType There are 3 update types=>widget, configure_widget, widget_component
     * @return WFWidgetPoolManager
     */
    public function getWidgetPoolManager($strUpdateType = 'widget'){
        if(! isset(self::$instance[__FUNCTION__][$strUpdateType])){
            $strFileName = $this->objFramework->getTypeFactory()->getString()->getUpperCamelCase($strUpdateType);
            require_once (self::getDirnameFile() . '/widget/'.$strFileName.'PoolManager.php');
            $strClassName = 'WF'.$strFileName.'PoolManager';
            self::$instance[__FUNCTION__][$strUpdateType] = new $strClassName($this->objFramework);
        }
        return self::$instance[__FUNCTION__][$strUpdateType];
    }
    /**
     *\brief Description
     * This method will return object of WFWidgetsNewInfoXmlManager
     * @return WFWidgetsNewInfoXmlManager
     */
    public function getWidgetsNewInfoXmlManager(){
        $key = null !== $this->objFramework ? get_class($this->objFramework) : 'null';
        if(! isset(self::$instance[__FUNCTION__][$key])){
            require_once (self::getDirnameFile() . '/WidgetsNewInfoXmlManager.php');
            self::$instance[__FUNCTION__][$key] = new WFWidgetsNewInfoXmlManager($this->objFramework);
        }
        return self::$instance[__FUNCTION__][$key];
    }
    /**
     *\brief Description
     * This method will return object of WFWidgetInfoXmlManager
     * @return WFWidgetInfoXmlManager
     */
    public function getWidgetInfoXmlManager(){
        $key = null !== $this->objFramework ? get_class($this->objFramework) : 'null';
        if(! isset(self::$instance[__FUNCTION__][$key])){
            require_once (self::getDirnameFile() . '/WidgetInfoXmlManager.php');
            self::$instance[__FUNCTION__][$key] = new WFWidgetInfoXmlManager($this->objFramework);
        }
        return self::$instance[__FUNCTION__][$key];
    }
    /**
     *\brief Description
     * This method will return object of WFWidgetComponentInfoXmlManager
     * @return WFWidgetComponentInfoXmlManager
     */
    public function getWidgetComponentInfoXmlManager(){
        $key = null !== $this->objFramework ? get_class($this->objFramework) : 'null';
        if(! isset(self::$instance[__FUNCTION__][$key])){
            require_once (self::getDirnameFile() . '/WidgetComponentInfoXmlManager.php');
            self::$instance[__FUNCTION__][$key] = new WFWidgetComponentInfoXmlManager($this->objFramework);
        }
        return self::$instance[__FUNCTION__][$key];
    }
    /**
     *\brief Description
     * This method will return object of WFWidgetsNewManager
     * @return WFWidgetsNewManager
     */
    public function getWidgetsNewManager(){
        if(! isset(self::$instance[__FUNCTION__])){
            require_once (self::getDirnameFile() . '/WidgetsNewManager.php');
            self::$instance[__FUNCTION__] = new WFWidgetsNewManager($this->objFramework);
        }
        return self::$instance[__FUNCTION__];
    }
    /**
     *\brief Description
     * This method will return object of WFWidgetPoolInterface
     * @return WFWidgetPoolInterface
     */
    public function getWidgetPoolInterface(){
        if(! isset(self::$instance[__FUNCTION__])){
            require_once (self::getDirnameFile() . '/../widget/Interface.php');
            self::$instance[__FUNCTION__] = new WFInterface($this->objFramework);
        }
        return self::$instance[__FUNCTION__];
    }
    /**
     *\brief Description
     * This method will return object of WFSimplexmlObject
     * @return WFSimplexml
     */
    public function getSimplexml($strPathOrDom = null){
        return $this->objFramework->getDomFactory()->getSimplexml($strPathOrDom);
    }
    /**
     *\brief Description
     * This method will return object of WFParameter
     * Use to generate SQL
     * @return AParameter
     */
    public function getParameter($mix = null){
        return $this->objFramework->getParameter($mix);
    }
    /**
     *\brief Description
     * This method will return object of WFSql
     * Use to generate Sql
     * @return ASql
     */
    public function getSql(){
        $strDBType = $this->objFramework->getConfigFactory()->getConfig()->getDbConfigType();
        $strSuffix = $this->objFramework->getTypeFactory()->getString()->getUpperCamelCase($strDBType);
        if(! isset(self::$instance[__FUNCTION__])){
            require_once (self::getDirnameFile() . '/../common/db/Sql' . $strSuffix . '.php');
        }
        $strFuncName = 'WFSql' . $strSuffix;
        self::$instance[__FUNCTION__] = new $strFuncName($this->objFramework);
        return self::$instance[__FUNCTION__];
    }
    /**
     *\brief Description
     * This method will return object of WFFixtures
     * Use to generate Default Data of unit test
     * @return WFFixtures
     */
    public function getFixtures(){
        return $this->objFramework->getDbFactory()->getFixtures();
    }
    /**
     *\brief Description
     * This method will return object of WFExitCode
     * Use to generate cmd Exit Code
     * @return WFExitCode
     */
    public function getWidgetPoolExitCode(){
        return $this->objFramework->getConfigFactory()->getExitCode();
    }
    /**
     *\brief Description
     * This method will return object of WFIOFactory
     * @return WFIOFactory
     */
    public function getIOFactory(){
        return $this->objFramework->getIOFactory();
    }
    /**
     *\brief Description
     * This method will return object of WFLogger
     * @return WFLogger
     */
    public function getLogger($name = null){
        return $this->objFramework->getLogger($name);
    }
}
